﻿using Token.Piker.Core.Security;
using Token.Piker.Core.Photo;
namespace Token.Piker.Web.AJAX
{
    /// <summary>
    /// Like 的摘要说明
    /// </summary>
    public class Like : BaseAjaxHandler
    {
        public class responseTemplate
        {
            public string uid;
            public string pid;
        }

        protected override void Mapping()
        {
            OprationMap["like"] = "LikePhoto";
        }

        public void LikePhoto()
        {
            if (Context.Request.HttpMethod != "POST")
                return;
            string uid = Context.Request.Form["uid"];
            string pid = Context.Request.Form["pid"];

            if (ValidLiked(uid, pid))
            {
                //添加新的喜欢信息


                //回发数据
                IsSuccess = true;
                responseTemplate model = new responseTemplate();
                model.uid = uid;
                model.pid = pid;
                ResponseTemplate(model);

            }
            else
            {
                IsSuccess = false;
            }


        }

        protected bool ValidLiked(string uid, string pid)
        {
            //check User 权限
            //if (!HasRight(AbstractUser.ERole.已验证))
            //return;

            //查看是否喜欢过
            if (PhotoProxy.IsLikedByUser(uid,pid))
            {
                return false;
            }
            else
            {
                return true;
            }

            
        }
    
    }
}